package com.rui.study.micro.key.manage.service.impl;

import com.rui.study.commons.util.RandomUtil;
import com.rui.study.commons.util.StringUtil;
import com.rui.study.micro.key.manage.mapper.KeyMapper;
import com.rui.study.micro.key.manage.service.KeyService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class KeyServiceImpl implements KeyService {

    private static final Logger LOGGER = LoggerFactory.getLogger(KeyServiceImpl.class);

    @Autowired
    private KeyMapper keyMapper;


    @Override
    public String getSalt(String accountId) {
        String salt = keyMapper.selectUserPwdSalt(accountId);
        if (StringUtil.isEmpty(salt)) {
            salt = RandomUtil.uuid();
            keyMapper.insertUserPwdSalt(accountId, salt);
        }
        return salt;
    }

//    @Override
//    public String createSaltedPwd(CrtSalPwdDTO crtSalPwdDTO) {
//        /* 变量准备 */
//        String accountId = crtSalPwdDTO.getAccountId();
//        String md5edPwd = crtSalPwdDTO.getMd5edPwd();
//
//        String salt = keyMapper.selectUserPwdSalt(accountId);
//        if (StringUtil.isEmail(salt)) {
//            salt = RandomUtil.uuid();
//            keyMapper.insertUserPwdSalt(accountId, salt);
//        }
//        return MD5Util.encrypt(md5edPwd + salt);
//    }
}
